<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-form :model="queryEnterpriseParams" ref="queryFormEnterprise" size="small" :inline="true"
                 v-show="showSearch" label-width="100px">
          <el-form-item label="企业名称" prop="enterpriseName">
            <el-input v-model="queryEnterpriseParams.enterpriseName" placeholder="请输入企业名称" clearable
                      @keyup.enter.native="handleQueryEnterprise" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini"
                       @click="handleQueryEnterprise">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini"
                       @click="resetQueryEnterprise">重置</el-button>
            <el-button type="primary" size="mini" @click="saveSelectEnterprise">确定</el-button>
          </el-form-item>
        </el-form>
        <el-table ref="tableEnterprise" v-loading="loading" style="width: 100%"
                  @selection-change="handleSelectionChangeEnterprise" :data="infoList">
          <el-table-column type="selection" width="45" align="center" />
          <el-table-column label="企业名称" align="center" prop="enterpriseName" />
          <el-table-column label="联系人" align="center" prop="contacts" />
          <el-table-column label="联系电话" align="center" prop="telephone"
                           show-overflow-tooltip="true" />
        </el-table>
        <pagination v-show="total1 > 0" :total="total1" :page.sync="queryEnterpriseParams.pageNum"
                    :limit.sync="queryEnterpriseParams.pageSize" @pagination="getEnterpriseList" />
      </el-col>
    </el-row>
  </div>
</template>
<script>
import {  supplierList } from "@/api/enterprise/info";
export default {
  name:"supplier",
  data(){
    return{
      // 显示搜索条件
      showSearch: true,
      infoList: [],
      // 选中数组
      bankNo: [],
      bankName: [],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      total1: 0,
      queryEnterpriseParams: {
        pageNum: 1,
        pageSize: 5,
        enterpriseName: null,
        markAs: '1',
        classificationId: null
      },
    }
  },
  created() {
    this.getEnterpriseList();
  },
  methods:{
    /** 搜索按钮操作 */
    handleQueryEnterprise() {
      this.queryEnterpriseParams.pageNum = 1;
      this.getEnterpriseList();
    },
    getEnterpriseList() {
      this.loading = true;
      supplierList(this.queryEnterpriseParams).then(response => {
        this.infoList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    /** 重置按钮操作 */
    resetQueryEnterprise() {
      this.resetForm("queryFormEnterprise");
      this.handleQueryEnterprise();
    },
    saveSelectEnterprise() {
      this.$emit('select-enterprise', {
        bankNo: this.bankNo.toString(),
        bankName: this.bankName.toString()
      });
    },
    handleSelectionChangeEnterprise(selection) {
      if (selection.length > 1) {
        this.$refs.tableEnterprise.clearSelection(); // 清空所有选择
        this.$refs.tableEnterprise.toggleRowSelection(selection.pop()); // 设置选择项
      } else {
        this.bankNo = selection.map(item => item.bankNo)
        this.bankName = selection.map(item => item.bankName)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      }
    },
  }
}
</script>
<style scoped lang="scss">

</style>
